package com.nfit.service.impl.adminuser;

import com.nfit.dao.AdminUserMapper;
import com.nfit.entity.AdminUser;
import com.nfit.entity.Transactions;
import com.nfit.entity.User;
import com.nfit.service.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class AdminUserServiceImpl implements AdminUserService {
    @Autowired
    private AdminUserMapper dao;
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public AdminUser login(AdminUser adminUser) {
        AdminUser login = dao.login(adminUser);
        if (login != null) {
            redisTemplate.opsForValue().set(login.getUsername(), String.valueOf(login.getAdminId()));
            return login;
        }
        return null;
    }

    @Override
    public List<AdminUser> selectAll() {
        return dao.selectAll();
    }

    @Override
    public int insert(AdminUser adminUser) {
        if (dao.login(adminUser) == null) {
            int result = dao.insert(adminUser);
            return result;
        }
        return 0;
    }

    @Override
    public AdminUser selectAdminUserById(String adminId) {
        AdminUser adminUser = dao.selectAdminUserById(adminId);
        return adminUser;
    }

    @Override
    public int updateAdminUser(AdminUser adminUser) {
        int result = dao.updateAdminUser(adminUser);
        return result;
    }

    @Override
    public int deleteAdminUserById(String adminId) {
        int result = dao.deleteAdminUserById(adminId);
        return result;
    }
}
